package com.jiuzhe.commercial.ui.house;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.amap.api.services.help.Tip;
import com.jiuzhe.commercial.R;
import com.jiuzhe.commercial.base.BaseActivity;
import com.jiuzhe.commercial.utils.UIUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by huanghao on 2018/6/2.
 */

public class AddHomeStayActivity2 extends BaseActivity {
    @BindView(R.id.et_city)
    TextView etCity;
    @BindView(R.id.et_area)
    EditText etArea;
    @BindView(R.id.et_room_num)
    EditText etRoomNum;
    private Tip tip;
    private String regionId;
    private String city;
    private String area;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_add_home_stay);
        setTitle("房源地址");
        setRringTitle("下一步");
        setOnClik();
    }

    private void setOnClik() {
        tv_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addHouseLocation();
            }
        });
    }



    @OnClick({R.id.et_city,R.id.et_area})
    public void onclick(View view) {
        switch (view.getId()) {
            case R.id.et_city:
                Intent intent = new Intent(this, CityListSelectActivity2.class);
                startActivityForResult(intent, 2);
                break;

            case R.id.et_area:
              //  Intent intent2 = new Intent(this, SearchResultActivity.class);
              //  intent2.putExtra("city",city);
               // intent2.putExtra("area",area);
              //  startActivityForResult(intent2, 0);
                break;
        }
    }


    @Override
    protected void loadData() {

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

            if (requestCode == 0 && resultCode == 1) {
                tip = data.getParcelableExtra("tip");
                etArea.setText(tip.getAddress());
            }

        if (requestCode == 2 && resultCode == 3) {
            city = data.getStringExtra("city");
            area = data.getStringExtra("area");
            etCity.setText(city + area);
         }
        }


    private void addHouseLocation() {
        String houseCity = etCity.getText().toString().trim();
        String houseArea = etArea.getText().toString().trim();
        String roomNum = etRoomNum.getText().toString().trim();
        if (TextUtils.isEmpty(houseCity)) {
            UIUtils.showToastSafe("请选择添加房源城市地区！");
            return;
        }
        if (TextUtils.isEmpty(houseArea)) {
            UIUtils.showToastSafe("请选择添加房源具体地址！");
            return;
        }
        if (TextUtils.isEmpty(roomNum)) {
            UIUtils.showToastSafe("请输入添加房源具体房号！");
            return;
        }


    }
    }
